package com.jxzyk.config;

import android.content.Context;

import com.core.config.ConfigSeting;
import com.core.util.L;
import com.core.util.Sharepf;
import com.core.util.T;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.DbUtils.DaoConfig;
import com.lidroid.xutils.HttpUtils;

public class DefaultSettings extends ConfigSeting {
	private Context context;
	private String AppName;
	private static DbUtils dbUtils;
	private static HttpUtils httpUtils;

	public DefaultSettings(Context applicationContext) {
		this.context = applicationContext;
		AppName = context.getPackageName();
	}

	@Override
	public void SetingLog(boolean open) {
		L.create(AppName);
		L.i("Log install..." + open);
		L.DEBUG = open;
	}

	@Override
	public void SettingToast() {
		L.i("toast install...");
		T.create(context);
	}

	@Override
	public void SettingSharepreference() {
		L.i("Sharepf install...");
		Sharepf.getInstance(context);
	}

	@Override
	public void SettingViewAnnotations(boolean open) {
//		L.i("ViewUtils install..." + open);
//		ViewUtils.DEBUG = open;
	}

	@Override
	public HttpUtils SettingNetUitl() {
		if (httpUtils == null) {
			httpUtils = new HttpUtils();
			L.i("HttpUtils install...");
		}
		return httpUtils;
	}

	@Override
	public DbUtils SettingDb(boolean debug) {
		DaoConfig daoConfig = new DaoConfig(context);
		String dbName = AppName + ".db";
		daoConfig.setDbName(dbName);
		dbUtils = DbUtils.create(daoConfig).configDebug(debug);
		L.i("DbUtils install...dbName:" + dbName);
		return dbUtils;
	}

	@Override
	public Object getDb() {
		if (dbUtils == null) {
			L.d("not setting db……");
			return null;
		}
		return dbUtils;
	}

	@Override
	public Object getNet() {
		if (httpUtils == null) {
			httpUtils = new HttpUtils();
			L.i("HttpUtils install...");
		}
		return httpUtils;
	}

}
